<template>
  <div class="home">
      <!-- 卡片 -->
      <div class="card-wrapper">
        <el-card class="card-item">
          <div class="card-icon-wrapper">
            <el-icon class="card-icon"><goods /></el-icon>
          </div>
          <div class="card-content-wrapper">
            <span class="card-title">
              今日订单数
            </span>
            <span class="card-content">
              1888
            </span>
          </div>
        </el-card>

        <el-card class="card-item">
          <div class="card-icon-wrapper">
            <el-icon class="card-icon"><user /></el-icon>
          </div>
          <div class="card-content-wrapper">
            <span class="card-title">
              今日日活
            </span>
            <span class="card-content">
              1888
            </span>
          </div>
        </el-card>

        <el-card class="card-item">
          <div class="card-icon-wrapper">
            <el-icon class="card-icon"><refresh /></el-icon>
          </div>
          <div class="card-content-wrapper">
            <span class="card-title">
              转化率
            </span>
            <span class="card-content">
              1888
            </span>
          </div>
        </el-card>
      </div>

      <!-- 折线图 -->
      <div id="echarts-content"></div>
  </div>
</template>

<script lang="ts" setup>
  import {onMounted} from 'vue'
  import {Goods,User,Refresh} from '@element-plus/icons-vue'
  import * as echarts from 'echarts';
  type EChartsOption = echarts.EChartsOption;

  let option: EChartsOption;

    option = {
      title: {
        text: '系统折线图'
      },
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'cross',
          label: {
            backgroundColor: '#6a7985'
          }
        }
      },
      legend: {
        data: ['新增注册', '付费用户', '活跃用户', '订单数', '当日净收入']
      },
      toolbox: {
        feature: {
          saveAsImage: {}
        }
      },
      grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
      },
      xAxis: [
        {
          type: 'category',
          boundaryGap: false,
          data: ['2022-02-04', '2022-02-05', '2022-02-06', '2022-02-07', '2022-02-08', '2022-02-09', '2022-02-10']
        }
      ],
      yAxis: [
        {
          type: 'value'
        }
      ],
      series: [
        {
          name: '新增注册',
          type: 'line',
          stack: 'Total',
          areaStyle: {},
          emphasis: {
            focus: 'series'
          },
          data: [120, 132, 101, 134, 90, 230, 210]
        },
        {
          name: '付费用户',
          type: 'line',
          stack: 'Total',
          areaStyle: {},
          emphasis: {
            focus: 'series'
          },
          data: [220, 182, 191, 234, 290, 330, 310]
        },
        {
          name: '活跃用户',
          type: 'line',
          stack: 'Total',
          areaStyle: {},
          emphasis: {
            focus: 'series'
          },
          data: [150, 232, 201, 154, 190, 330, 410]
        },
        {
          name: '订单数',
          type: 'line',
          stack: 'Total',
          areaStyle: {},
          emphasis: {
            focus: 'series'
          },
          data: [320, 332, 301, 334, 390, 330, 320]
        },
        {
          name: '当日净收入',
          type: 'line',
          stack: 'Total',
          label: {
            show: true,
            position: 'top'
          },
          areaStyle: {},
          emphasis: {
            focus: 'series'
          },
          data: [820, 932, 901, 934, 1290, 1330, 1320]
        }
      ]
    };

  onMounted(() => {
    let chartDom = document.getElementById('echarts-content')!;
    let myChart = echarts.init(chartDom);
    option && myChart.setOption(option);
  })
  
</script>

<style lang="scss" scoped>
.home {
  flex: 1;
  overflow: auto;
  background-color: #fff;
  border-radius: 8px;
  margin: 12px;
  padding: 12px;
}

#echarts-content {
  width: 100%;
  height: 400px;
  margin-top: 48px;
}

.card-wrapper {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  width: 100%;

  .card-item {
    height: 120px;
    width: 320px;
    cursor: pointer;

    &+.card-item {
      margin-left: 24px;
    }

    &:hover {
      .card-icon-wrapper {
        background-color: $hs-color;
        color: #fff;
      }  
    }

    .card-icon-wrapper {
      color: $hs-color;
      padding: 8px;
      border-radius: 6px;
      transition-property: all;
      transition-duration: .3s;
    }

    .card-icon {
      font-size: 52px;
    }

    .card-content-wrapper {
      display: flex;
      flex-direction: column;
      padding-right: 12px;
    }

    .card-content {
      color: #666;
      font-size: 20px;
      font-weight: 700;
    }

    .card-title {
      font-weight: 600;
      line-height: 18px;
      color: rgba(0,0,0,.45);
      font-size: 16px;
      margin-bottom: 12px;
    }

  }
}

:deep(.el-card__body) {
  display: flex;
  align-items: center;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  justify-content: space-between;
}
</style>
